﻿Ext.namespace('EHSubmit.BBS.View');



//var expander = new Ext.ux.grid.RowExpander({
//    tpl: new Ext.Template(
//            '<p><br>&nbsp;&nbsp;回复人：{RestoreName}</p><br>',
//            '<p>&nbsp;&nbsp;内&nbsp;&nbsp;&nbsp;容：{RestoreBody}</p><br>'
//        )
//});


EHSubmit.BBS.View.addRes = function addRes() {

    EHSubmit.showWin(EHSubmit.BBS.AddRes.window);
    Ext.getCmp('AddResTitle').setValue('回复：' + Topic);
    Ext.getCmp('AddResTitle_Name').setValue(UserName);
};

//---------------设置列字段-------------------------------
EHSubmit.BBS.View.colModel = new Ext.grid.ColumnModel([

//expander,
        new Ext.grid.RowNumberer(),
        { header: '回复ID', id: 'RID', dataIndex: 'RID', hidden: true, hideable: false },
        { header: '回复人', id: 'RestoreName', dataIndex: 'RestoreName', width: 650 },
        //{ header: '回复内容', id: 'RestoreBody', dataIndex: 'RestoreBody', hidden: true, hideable: false },
        {header: '回复人ID', id: 'RestoreID', dataIndex: 'RestoreID', hidden: true, hideable: false },
        { header: '角色', id: 'Role', dataIndex: 'Role', width: 100 },
        { header: '回复时间', id: 'ResTime', dataIndex: 'ResTime', width: 150, renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s') }
        
    ]);



        EHSubmit.BBS.View.store = new Ext.data.Store({
            id: 'ViewGridStore',
            baseParams: { Op: 'ViewPage', AnnID: AnnID },      //需要传递操作参数
            proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'BBSHandler.ashx' }),

            reader: new Ext.data.JsonReader({
                isSuccess: 'success',
                totalProperty: 'totalProperty',
                root: 'root'
            }, [
        { name: 'RID' },
            //{ name: 'Department' },
        {name: 'ResAnnID' },
        { name: 'RestoreBody' },
        { name: 'RestoreName' },
        { name: 'RestoreID' },
        { name: 'Role' },
        { name: 'ResTime' }
        ]),
            listeners: {
                /// 加载异常处理
                //            load:function()
                //            {
                //                for (var i = 0; i < Ext.getCmp('ViewGrid').getStore().getCount(); i++) {
                //                    row = Ext.getCmp('ViewGrid').view.getRow(i);
                //                    //Ext.getCmp('expender')[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
                //                    Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
                //                }
                //            },

                beforeload: function(thisStore, obj) {
                    thisStore.setBaseParam('AnnID', AnnID);
                },

                exception: function(proxy, type, action, options, response) {
                    Ext.MessageBox.alert('数据加载错误!', '请与管理员联系');

                }
            }
        });




EHSubmit.BBS.View.grid = {
    xtype: 'grid',
    id: 'ViewGrid',
    //plugins: expander,
    store: EHSubmit.BBS.View.store,
    cm: EHSubmit.BBS.View.colModel,
    sm: new Ext.grid.RowSelectionModel({
        singleSelect: true             // 一次只选一个
    }),
    layout: 'fit',
    loadMask: true,
    height: 410,
    frame: true,
    //columnLines: true,
    buttonAlign: 'left',
    viewConfig: {
        forceFit: true,
        enableRowBody: true,
        showPreview: true,
        getRowClass: function(record, rowIndex, p, ds) {
            if (this.showPreview) {
                p.body = '<p><br>&nbsp;&nbsp;回复人：' + record.data.RestoreName
                            + '</p><br><p>&nbsp;&nbsp;内&nbsp;&nbsp;&nbsp;容：' + record.data.RestoreBody + '</p><br>';
                return 'x-grid3-row-expanded';
            }
            return 'x-grid3-row-collapsed';
        }
    },
    tbar: [{
        pressed: true,
        enableToggle: true,
        text: '回复详情',
        iconCls: 'add',
        toggleHandler: toggleDetails
    }, '-',
        {
            text: '发表回复',
            tooltip: '发表回复',
            iconCls: 'icon-write',
            handler: EHSubmit.BBS.View.addRes
        }
        ],

    bbar: {
        id: 'ViewGridPage',
        xtype: 'paging',
        pageSize: 15,                 //只是起计算页数的作用，不影响表面,内部影响start 和 limit
        store: EHSubmit.BBS.View.store,
        displayInfo: true,
        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
        emptyMsg: "没有记录",
        items: [
            {
                text: '回复',
                tooltip: '回复',
                iconCls: 'icon-write',
                handler: EHSubmit.BBS.View.addRes
            }
            ]
    },
    listeners: {
        render: function(thisGrid) {
        //----------请求单页数据-----------------
            //Ext.getCmp('ViewGridPage').refresh.hide();
            thisGrid.store.load({ params: { start: 0, limit: 15, AnnID: AnnID} });
        },
        cellclick: function(thisGrid, rowIndex, columnIndex, e) {
            if (columnIndex != 0) {
                row = thisGrid.view.getRow(rowIndex);
                //Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
                if (Ext.fly(row).hasClass('x-grid3-row-collapsed')) {
                    Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
                }
                else {
                    Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');   
                }

            }
        }
    }
};

function toggleDetails(btn, pressed) {
    var view = Ext.getCmp('ViewGrid').getView();
    view.showPreview = pressed;
    view.refresh();
}

EHSubmit.BBS.View.AnnInfo = {
    xtype:'portal',
    border:false,
    html:'<div id=Add_View_AnnInfo></div>'
}


EHSubmit.BBS.View.panel = {
    xtype: 'panel',
    margins: '0',
    title: '标题信息',
    height: 130,
    bodyStyle:'font-size:8pt',
    autoScroll: true, 
    //border: true,
    items: [EHSubmit.BBS.View.AnnInfo]
};

EHSubmit.BBS.View.Tab = {
    id: 'ViewTab',
    title: '答疑-回复',
    bodyStyle: 'padding:5px;',
    closable: true,
    frame: false,
    border: false,
    items: [EHSubmit.BBS.View.panel, EHSubmit.BBS.View.grid]
};